//
//  ExploreAudioDetailViewController.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/9/1.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "ExploreAudioDetailViewController.h"
#import "MusicManager.h"
#import "DetailAuthorIntroduceCell.h"
#import "ExploreAVListView.h"
#import "DetailBottomListView.h"
#import "DerailIntroduceCell.h"
#import "DetailCommentCell.h"
#import "ReportViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "TimerActionsheetView.h"
#import "RewardView.h"
@interface ExploreAudioDetailViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UIImageView *imageView;
@property(nonatomic,strong)UIButton *playOrPauseBtn;
@property(nonatomic,strong)UISlider *slider;
@property(nonatomic,strong)UILabel *CurrentTimeLabel;
@property(nonatomic,strong)UILabel *totlaLabel;
@property(nonatomic,strong)NSTimer *timer;
@property(nonatomic,strong)UIView *headerView;
@property(nonatomic,strong)UITableView *tablview;
@property(nonatomic,strong)RewardView *rewardview;
@end

@implementation ExploreAudioDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createTablview];
    // Do any additional setup after loading the view.
}

-(void)createTablview{
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(WIDTH - 30, 6, 40, 20);
    rightBtn.backgroundColor = [UIColor cyanColor];
    UIBarButtonItem *rightBtnItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    [self.navigationItem setRightBarButtonItem:rightBtnItem];
    self.tablview = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, WIDTH, HEIGHT - 64 ) style:UITableViewStyleGrouped];
    [self.view addSubview:self.tablview];
    self.tablview.dataSource = self;
    self.tablview.delegate = self;
    [self.tablview registerClass:[DetailAuthorIntroduceCell class] forCellReuseIdentifier:@"DetailAuthorIntroduceCell"];
    [self.tablview registerClass:[DerailIntroduceCell class] forCellReuseIdentifier:@"DerailIntroduceCell"];
    [self.tablview registerClass:[DetailCommentCell class] forCellReuseIdentifier:@"DetailCommentCell"];
}
#pragma makr - tablview的代理方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 5;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createAvPlayerViewInView:cell.contentView];
        return cell;
    }else if (indexPath.section == 1){
        DetailAuthorIntroduceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailAuthorIntroduceCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if(indexPath.section == 2){
        DerailIntroduceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DerailIntroduceCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if(indexPath.section == 3){
        UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        DetailBottomListView *contentView = [[DetailBottomListView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, scaleTopAndBottom(240))];
        [cell.contentView addSubview:contentView];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        DetailCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailCommentCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return scaleTopAndBottom(415);
    }else if (indexPath.section == 1){
        return scaleTopAndBottom(175);
    }else if(indexPath.section == 2){
        return scaleTopAndBottom(300);
    }else if(indexPath.section == 3){
        return scaleTopAndBottom(240);
    }else{
        return scaleTopAndBottom(100);
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return CGFLOAT_MIN;
    }else{
        return scaleTopAndBottom(50);
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0 || section == 1 || section == 3) {
        return scaleTopAndBottom(5);
    }else if(section == 2){
        return scaleTopAndBottom(175);
    }else{
        return scaleTopAndBottom(60);
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    if (section == 0) {
        return nil;
    }else if (section == 1){
        return [self createHeaderViewAboutUI:@"作者介绍" AndAddSubviewToFatherview:view];
    }else if (section == 2){
        return [self createHeaderViewAboutUI:@"详情介绍" AndAddSubviewToFatherview:view];
    }else if(section == 3){
         [self addHeaderViewContent:view AndChineseTitle:@"最新推荐" AndEnglishTitle:@"The latest recommended"];
        return view;
    }else{
        [self creaeCommentCellHeader:view];
        return view;
    }
    
}
//创建tableview的头部视图
-(UIView *)createHeaderViewAboutUI:(NSString *)headerTitle AndAddSubviewToFatherview:(UIView *)fatherView{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor yellowColor];
    [fatherView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(fatherView.mas_centerY);
        make.left.equalTo(fatherView.mas_left).offset(scaleLeftAndRight(10));
        make.height.mas_equalTo(25);
        make.width.mas_equalTo(scaleLeftAndRight(2));
    }];
    UILabel *lable = [[UILabel alloc] init];
    [fatherView addSubview:lable];
    lable.text = headerTitle;
    [lable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view.mas_right).offset(scaleLeftAndRight(10));
        make.top.equalTo(fatherView.mas_top);
        make.bottom.equalTo(fatherView.mas_bottom);
        make.right.equalTo(fatherView.mas_right).offset(scaleLeftAndRight(-10));
    }];
    return fatherView;
}
#pragma mark -头部视图
-(void)addHeaderViewContent:(UIView *)titleView AndChineseTitle:(NSString *)chineTile AndEnglishTitle:(NSString *)engTitle{
    UILabel *label = [[UILabel alloc] init];
    label.text = chineTile;
    label.adjustsFontSizeToFitWidth = YES;
    label.textAlignment = NSTextAlignmentCenter;
    [titleView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(titleView.mas_centerX);
        make.centerY.equalTo(titleView.mas_centerY).offset(scaleTopAndBottom(-5));
        make.width.mas_equalTo(scaleLeftAndRight(80));
        make.height.mas_equalTo(scaleTopAndBottom(20));
    }];
    UIView *view1 = [[UIView alloc] init];
    view1.backgroundColor = [UIColor lightGrayColor];
    [titleView addSubview:view1];
    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleView.mas_left).offset(scaleLeftAndRight(80));
        make.centerY.equalTo(titleView.mas_centerY).offset(scaleTopAndBottom(-5));
        make.height.mas_equalTo(scaleTopAndBottom(1));
        make.right.equalTo(label.mas_left).offset(scaleLeftAndRight(-5));
    }];
    UIView *view2 = [[UIView alloc] init];
    view2.backgroundColor = [UIColor lightGrayColor];
    [titleView addSubview:view2];
    [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(titleView.mas_right).offset(scaleLeftAndRight(-80));
        make.centerY.equalTo(titleView.mas_centerY).offset(scaleTopAndBottom(-5));
        make.height.mas_equalTo(scaleTopAndBottom(1));
        make.left.equalTo(label.mas_right).offset(scaleLeftAndRight(5));
    }];
    UILabel *bottomLabel = [[UILabel alloc] init];
    bottomLabel.text = engTitle;
    bottomLabel.adjustsFontSizeToFitWidth = YES;
    bottomLabel.textAlignment = NSTextAlignmentCenter;
    [titleView addSubview:bottomLabel];
    [bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(label.mas_bottom).offset(0);
        make.width.mas_equalTo(WIDTH);
        make.height.mas_equalTo(scaleTopAndBottom(20));
        make.left.equalTo(titleView.mas_left);
    }];
    
}

-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerView = [[UIView alloc] init];
    footerView.backgroundColor = [UIColor purpleColor];
    if (section == 2) {
        UIView *customFooterView = [[UIView alloc] init];
        UIButton *reportBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [customFooterView addSubview:reportBtn];
        [reportBtn setTitle:@"举报" forState:UIControlStateNormal];
        [reportBtn addTarget:self action:@selector(GotoReportPage) forControlEvents:UIControlEventTouchUpInside];
        [reportBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [reportBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(customFooterView);
            make.top.equalTo(customFooterView.mas_top).offset(scaleTopAndBottom(10));
            make.size.mas_equalTo(CGSizeMake(scaleLeftAndRight(100), scaleTopAndBottom(20)));
        }];
        UILabel *timelabel = [[UILabel alloc] init];
        timelabel.text = @"发布于 2017-09-01";
        [customFooterView addSubview:timelabel];
        [timelabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(customFooterView.mas_top).offset(scaleTopAndBottom(10));
            make.left.equalTo(customFooterView.mas_left).offset(scaleLeftAndRight(10));
            make.right.equalTo(reportBtn.mas_right).offset(scaleLeftAndRight(-10));
            make.height.mas_equalTo(scaleTopAndBottom(20));
        }];
        UIView *lineView = [[UIView alloc] init];
        [customFooterView addSubview:lineView];
        lineView.backgroundColor = [UIColor lightGrayColor];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(timelabel.mas_bottom).offset(scaleTopAndBottom(30));
            make.centerX.equalTo(customFooterView.mas_centerX);
            make.left.equalTo(customFooterView.mas_left).offset(scaleLeftAndRight(20));
            make.height.mas_equalTo(scaleTopAndBottom(1));
        }];
        UIButton *uploadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [uploadBtn setTitle:@"上传我的作品" forState:UIControlStateNormal];
        [customFooterView addSubview:uploadBtn];
        uploadBtn.backgroundColor = [UIColor orangeColor];
        [uploadBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lineView.mas_bottom).offset(scaleTopAndBottom(20));
            make.centerX.equalTo(customFooterView.mas_centerX);
            make.left.equalTo(customFooterView.mas_left).offset(scaleLeftAndRight(20));
            make.height.mas_equalTo(scaleTopAndBottom(45));
        }];
        uploadBtn.layer.cornerRadius = 22.5;
        uploadBtn.layer.masksToBounds = YES;
        UIView *bottomView = [[UIView alloc] init];
        bottomView.backgroundColor = [UIColor purpleColor];
        [customFooterView addSubview:bottomView];
        [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.left.right.equalTo(customFooterView);
            make.height.mas_equalTo(scaleTopAndBottom(5));
        }];
        return customFooterView;
    }
    if (section == 4) {
        footerView.backgroundColor = [UIColor whiteColor];
        [self createCommentCellFooter:footerView];
    }
    return footerView;
}
-(void)GotoReportPage{
    ReportViewController *reportVc = [[ReportViewController alloc] init];
    [self.navigationController pushViewController:reportVc animated:YES];
}
/**
 创建评论界面的头部视图
 */
-(void)creaeCommentCellHeader:(UIView *)view{
    UIImageView *iconImageVeiw = [[UIImageView alloc] init];
    [view addSubview:iconImageVeiw];
    [iconImageVeiw mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(view);
        make.left.equalTo(view.mas_left).offset(scaleLeftAndRight(5));
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    UILabel *commentLabel = [[UILabel alloc] init];
    [view addSubview:commentLabel];
    [commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconImageVeiw.mas_right).offset(scaleLeftAndRight(5));
        make.top.bottom.right.equalTo(view);
    }];
    iconImageVeiw.backgroundColor = [UIColor redColor];
    commentLabel.text = @"评论";
    commentLabel.font = [UIFont systemFontOfSize:24];
}

/**
 创建评论界面的尾部视图
 */
-(void)createCommentCellFooter:(UIView *)view{
    UIView *backView = [[UIView alloc] init];
    backView.backgroundColor = [UIColor lightGrayColor];
    [view addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(view);
        make.left.equalTo(view.mas_left).offset(scaleLeftAndRight(5));
        make.height.mas_equalTo(scaleTopAndBottom(40));
        make.width.equalTo(view).multipliedBy(0.6);
    }];
    backView.layer.cornerRadius = 20;
    backView.layer.masksToBounds = YES;
    UITextField *textFild = [[UITextField alloc] init];
    textFild.placeholder = @"期待您的神评论";
    [backView addSubview:textFild];
    [textFild mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(backView);
        make.left.equalTo(backView.mas_left).offset(scaleLeftAndRight(10));
        make.height.mas_equalTo(scaleTopAndBottom(30));
        make.right.equalTo(backView.mas_right).offset(scaleLeftAndRight(-10));
    }];
    UIButton *commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [view addSubview:commentBtn];
    UIButton *praiseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [view addSubview:praiseBtn];
    UIButton *collectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [view addSubview:collectBtn];
    [commentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backView.mas_right).offset(scaleLeftAndRight(5));
        make.centerY.equalTo(view);
        make.top.equalTo(view.mas_top).offset(scaleTopAndBottom(10));
    }];
    [praiseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(commentBtn.mas_right).offset(scaleLeftAndRight(20));
        make.centerY.equalTo(view);
        make.top.equalTo(view.mas_top).offset(scaleTopAndBottom(10));
    }];
    [collectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(praiseBtn.mas_right).offset(scaleLeftAndRight(20));
        make.centerY.equalTo(view);
        make.top.equalTo(view.mas_top).offset(scaleTopAndBottom(10));
        make.right.equalTo(view.mas_right).offset(scaleLeftAndRight(-10));
        make.width.equalTo(@[commentBtn,praiseBtn]);
    }];
    praiseBtn.backgroundColor = [UIColor cyanColor];
    commentBtn.backgroundColor = [UIColor cyanColor];
    collectBtn.backgroundColor = [UIColor cyanColor];
}
//#pragma mark - UIScrollViewDelegate和取消区头的停滞效果
//- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
//    if ([scrollView isEqual:self.tablview]){
//    }
//    CGFloat sectionHeaderHeight = scaleTopAndBottom(50);
//    if (scrollView.contentOffset.y <=sectionHeaderHeight && scrollView.contentOffset.y >=  0) {
//        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
//    } else if (scrollView.contentOffset.y >=sectionHeaderHeight) {
//        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
//    }
//}
#pragma mark -创建音频播放器
-(void)createAvPlayerViewInView:(UIView *)view{
    /*******************设置头部视图的播放音频的页面******************************/
    _headerView = [[UIView alloc] init];
    _headerView.backgroundColor = [UIColor whiteColor];
    [view addSubview:_headerView];
    [_headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    _imageView = [[UIImageView alloc] init];
    _imageView.backgroundColor = [UIColor redColor];
    _imageView.userInteractionEnabled = YES;
    [_headerView addSubview:_imageView];
    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(_headerView);
        make.height.mas_equalTo(scaleTopAndBottom(210));
    }];
    _slider = [[UISlider alloc] init];
    [_slider addTarget:self action:@selector(progressAct:) forControlEvents:UIControlEventValueChanged];
    [_headerView addSubview:_slider];
    [_slider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(_headerView);
        make.top.equalTo(_imageView.mas_bottom);
        make.height.mas_equalTo(scaleTopAndBottom(3));
        
    }];
    _CurrentTimeLabel = [[UILabel alloc] init];
    _CurrentTimeLabel.textAlignment = NSTextAlignmentLeft;
    _CurrentTimeLabel.text = @"00:00";
    [_headerView addSubview:_CurrentTimeLabel];
    [_CurrentTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_headerView);
        make.top.equalTo(_slider.mas_bottom);
        make.size.mas_equalTo(CGSizeMake(scaleLeftAndRight(100), scaleTopAndBottom(10)));
    }];
    _totlaLabel = [[UILabel alloc] init];
    _totlaLabel.textAlignment = NSTextAlignmentRight;
    [_headerView addSubview:_totlaLabel];
    [_totlaLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_headerView);
        make.top.equalTo(_slider.mas_bottom);
        make.size.mas_equalTo(CGSizeMake(scaleLeftAndRight(100), scaleTopAndBottom(10)));
    }];
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_headerView addSubview:leftBtn];
    [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_headerView.mas_left).offset(scaleLeftAndRight(100));
        make.top.equalTo(_slider.mas_bottom).offset(scaleTopAndBottom(35));
        make.size.mas_equalTo(CGSizeMake(scaleLeftAndRight(20), scaleLeftAndRight(20)));
    }];
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_headerView addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_headerView.mas_right).offset(scaleLeftAndRight(-100));
        make.top.equalTo(_slider.mas_bottom).offset(scaleTopAndBottom(35));
        make.size.mas_equalTo(CGSizeMake(scaleLeftAndRight(20), scaleLeftAndRight(20)));
    }];
    _playOrPauseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_headerView addSubview:_playOrPauseBtn];
    [_playOrPauseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_headerView.mas_centerX);
        make.top.equalTo(_slider.mas_bottom).offset(scaleTopAndBottom(20));
        make.size.mas_equalTo(CGSizeMake(scaleLeftAndRight(50), scaleLeftAndRight(50)));
    }];
    UIButton *timeListBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [timeListBtn addTarget:self action:@selector(TimeListCellChoose:) forControlEvents:UIControlEventTouchUpInside];
    timeListBtn.backgroundColor = [UIColor redColor];
    [_headerView addSubview:timeListBtn];
    [timeListBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(scaleLeftAndRight(30), scaleTopAndBottom(40)));
        make.left.equalTo(_headerView.mas_left).offset(scaleLeftAndRight(20));
        make.top.equalTo(_slider.mas_bottom).offset(scaleTopAndBottom(20));
    }];
    leftBtn.tag = 1000;
    rightBtn.tag = 1001;
    _playOrPauseBtn.tag = 1002;
    [leftBtn addTarget:self action:@selector(MusicRuntimeChoose:) forControlEvents:UIControlEventTouchUpInside];
    [rightBtn addTarget:self action:@selector(MusicRuntimeChoose:) forControlEvents:UIControlEventTouchUpInside];
    [_playOrPauseBtn addTarget:self action:@selector(MusicRuntimeChoose:) forControlEvents:UIControlEventTouchUpInside];
    _slider.backgroundColor = [UIColor whiteColor];
    [_playOrPauseBtn setBackgroundImage:[UIImage imageNamed:@"playplay"] forState:UIControlStateNormal];
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"leftleft"] forState:UIControlStateNormal];
    [rightBtn setBackgroundImage:[UIImage imageNamed:@"rightright"] forState:UIControlStateNormal];
    _totlaLabel.backgroundColor = [UIColor clearColor];
/*************************************作品列表的页面展示*******************************/
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor lightGrayColor];
    [_headerView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(_headerView);
        make.height.mas_equalTo(scaleTopAndBottom(1));
        make.top.equalTo(_playOrPauseBtn.mas_bottom).offset(scaleTopAndBottom(10));
    }];
    UIButton *rewardBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rewardBtn.backgroundColor = [UIColor cyanColor];
    [rewardBtn addTarget:self action:@selector(showRewardView) forControlEvents:UIControlEventTouchUpInside];
    [_imageView addSubview:rewardBtn];
    [rewardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(40, 40));
        make.right.equalTo(_imageView.mas_right).offset(scaleLeftAndRight(-10));
        make.centerY.equalTo(_imageView.mas_centerY).offset(scaleTopAndBottom(20));
    }];
    ExploreAVListView *listView = [[ExploreAVListView alloc] initWithFrame:CGRectMake(0, scaleTopAndBottom(290), WIDTH, scaleTopAndBottom(125))];
    [_headerView addSubview:listView];
//    [listView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(_headerView.mas_left);
//        make.right.equalTo(_headerView.mas_right);
//        make.top.equalTo(lineView.mas_bottom);
//        make.height.mas_equalTo(scaleTopAndBottom(110));
//    }];
    self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timerAct) userInfo:nil repeats:YES];
    
    
}
-(void)showRewardView{
    UIView *backView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    backView.alpha = 0.5f;
    backView.backgroundColor = [UIColor blackColor];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removebackView:)];
    [backView addGestureRecognizer:tap];
    [self.view addSubview:backView];
    _rewardview = [[RewardView alloc] initWithFrame:CGRectMake(0, HEIGHT, WIDTH, scaleTopAndBottom(370))];
    [self.view addSubview:_rewardview];
    [UIView animateWithDuration:0.1 animations:^{
        [_rewardview mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.view);
            make.height.mas_equalTo(scaleTopAndBottom(370));
        }];
    }];
}
-(void)removebackView:(UITapGestureRecognizer *)tap{

    [UIView animateWithDuration:0.1 animations:^{
        UIView *view = tap.view;
        [view removeFromSuperview];
        [_rewardview removeFromSuperview];
    }];
}
/**
 定时器的选择
 */
-(void)TimeListCellChoose:(UIButton *)btn{
    UIView *backView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    backView.alpha = 0.5f;
    backView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:backView];
    TimerActionsheetView *timerAction = [[TimerActionsheetView alloc] initWithFrame:CGRectMake(0, HEIGHT, WIDTH, HEIGHT/2) WithTitlesArray:@[@"不开启",@"10分钟",@"20分钟",@"30分钟",@"60分钟",@"90分钟"]];
    [self.view addSubview:timerAction];
    __weak typeof(TimerActionsheetView *) weakTimesrAction = timerAction;
    [UIView animateWithDuration:0.5 animations:^{
        weakTimesrAction.frame = CGRectMake(0, HEIGHT/2, WIDTH, HEIGHT/2);
    }];
    
    timerAction.timeBlock = ^(NSString *times) {
        if ([times rangeOfString:@"分钟"].length <= 0 ) {
            
        }else{
            NSString *timeDuration = [NSString stringWithFormat:@"%@",[times componentsSeparatedByString:@"分"][0]];
            NSLog(@"试试%@",timeDuration);
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)([timeDuration integerValue] * 60 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                exit(0);
            });
        }
    };
    timerAction.closeBlock = ^{
        [UIView animateWithDuration:0.5 animations:^{
            [backView removeFromSuperview];
            weakTimesrAction.frame = CGRectMake(0, HEIGHT, WIDTH, HEIGHT/2);
        }];
    };
}
-(void)progressAct:(id)sender{
    [[MusicManager shareInfo] playerProgressWithProgressFloat:((UISlider*)sender).value];
}

- (void)timerAct{
    if ([MusicManager shareInfo].player.currentTime.timescale == 0 || [MusicManager shareInfo].player.currentItem.duration.timescale == 0) {
        return;
    }
    // 获得音乐总时长
    long long int totalTime = [MusicManager shareInfo].player.currentItem.duration.value / [MusicManager shareInfo].player.currentItem.duration.timescale;
    // 获得当前时间
    long long int currentTime = [MusicManager shareInfo].player.currentTime.value / [MusicManager shareInfo].player.currentTime.timescale;
    self.CurrentTimeLabel.text = [NSString stringWithFormat:@"%02lld:%02lld", currentTime / 60, currentTime % 60];
    self.totlaLabel.text = [NSString stringWithFormat:@"%02lld:%02lld", totalTime / 60, totalTime % 60];
    self.slider.maximumValue = totalTime;
    self.slider.minimumValue = 0;
    self.slider.value = currentTime;
    if (self.slider.value == totalTime) {
        [[MusicManager shareInfo] playNext];
        [self reloadDataWithIndex:[MusicManager shareInfo].index];
    }
}
-(void)MusicRuntimeChoose:(UIButton *)btn{
//    self.authotId = nil;
//    [MusicManager shareInfo].musicArray = self.listArray;
    if (btn.tag == 1000) {
        [_playOrPauseBtn setImage:[UIImage imageNamed:@"pause"] forState:UIControlStateNormal];
        [[MusicManager shareInfo] playPrevious];
        [self reloadDataWithIndex:[MusicManager shareInfo].index];
    }
    if (btn.tag == 1001) {
        [_playOrPauseBtn setImage:[UIImage imageNamed:@"pause"] forState:UIControlStateNormal];
        [[MusicManager shareInfo] playNext];
        [self reloadDataWithIndex:[MusicManager shareInfo].index];
    }
    if (btn.tag == 1002) {
        if ([MusicManager shareInfo].isPlay == YES) {
            [btn setImage:[UIImage imageNamed:@"play"] forState:(UIControlStateNormal)];
        }else{
            [btn setImage:[UIImage imageNamed:@"pause"] forState:(UIControlStateNormal)];
        }
        [[MusicManager shareInfo] playAndPause];
    }
    
}
- (void)reloadDataWithIndex:(NSInteger)index
{
    
//    // 寻找model
//    OpusListModel *model = [MusicManager shareInfo].musicArray[index];
//    [self getPersonDetailVcDataAccordingId:model.opusId];
//    // 改变图片 标题 音频
//    self.navigationItem.title = model.name;
//    // 修改播放歌曲
//    [[MusicManager shareInfo] replaceItemWithUrlString:model.filepath];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
